package com.echo.http;

import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;

/**
 * Byte[]类型的volley request
 * Created by EchoGe on 16/4/6.
 */
public class ByteArrayRequest extends Request<byte[]> {
    private final Response.Listener<byte[]> mListener;

    public ByteArrayRequest(String url, Response.Listener<byte[]> listener, Response.ErrorListener errorListener) {
        super(0, url, errorListener);
        mListener = listener;
    }

    @Override
    protected Response<byte[]> parseNetworkResponse(NetworkResponse response) {
        if (response == null) {
            return null;
        }
        if (response.statusCode != 200) {
            return null;
        }
        byte[] bytes = response.data;
        return Response.success(bytes, null);
    }

    @Override
    protected void deliverResponse(byte[] response) {
        if (mListener != null) {
            mListener.onResponse(response);
        }
    }
}
